package myalert

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type MACHINEMESSAGES struct {
	Msgtype string `json:"msgtype"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
}

func SendMachine(send_url, content string) {
	client := &http.Client{}
	msg := MACHINEMESSAGES{
		Msgtype: "text",
		Text: struct {
			Content string `json:"content"`
		}{Content: content},
	}
	sed_msg, _ := json.Marshal(msg)
	req, _ := http.NewRequest("POST", send_url, bytes.NewBuffer([]byte(sed_msg)))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("charset", "UTF-8")
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Printf("\n%q", string(body))
}
